package process

import (
	"encoding/json"
	"go_code/chatroom/server/message"
	"go_code/chatroom/server/utils"
)

type SmsProcess struct {

}

func (sp *SmsProcess) SendGroupMessageToOnlineUsers(msg *message.Message) {
	var smsMsg *message.SmsMessage

	_ = json.Unmarshal([]byte(msg.Data), &smsMsg)
	onlineUsers := userManager.GetAllOnlineUsers()

	for userId, up := range onlineUsers {
		if smsMsg.UserId == userId {
			continue
		}

		sp.sendToUser(msg, up)
	}
}

func (sp *SmsProcess) sendToUser(msg *message.Message, up *UserProcess) {
	t := &utils.Transport{
		Conn: up.Conn,
	}

	err := t.WritePkg(msg)
	if err != nil {
		return
	}
}
